package com.cartrentalsystem.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cartrentalsystem.domain.po.Repair;
import com.cartrentalsystem.domain.vo.RepairVo;
import com.cartrentalsystem.domain.vo.Result;
import com.cartrentalsystem.service.IRepairService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LHD
 * @since 2025-06-16
 */
@RestController
@RequestMapping("/repair")
@Slf4j
@RequiredArgsConstructor
public class RepairController {

    private final IRepairService repairService;

    @GetMapping("/list")
    public Result<Page<RepairVo>> list(@Param("page") Integer page, @Param("size") Integer size, @Param("status") Integer status, @Param("employeeName") String employeeName){
        log.info("page:{},size:{},status:{},employeeName:{}",  page, size, status,employeeName);
        Result<Page<RepairVo>> result =repairService.pageList(page, size,status,employeeName);
        log.info("result:{}",result);
        return result;
    }

    @PutMapping("/repairing/{id}")
    public Result<String> repairing(@PathVariable("id") Integer id
            , @Param("repairTime") LocalDate repairTime
            , @Param("repairExpectFinishTime") LocalDate repairExpectFinishTime){
        boolean b = repairService.updateRepairing(id, repairTime, repairExpectFinishTime);
        return b ? Result.success("更新成功") : Result.fail("更新失败");
    }

    @PutMapping("/repaired/{id}")
    public Result<String> repaired(@PathVariable("id") Integer id){
        boolean b = repairService.updateRepaired(id);
        return b ? Result.success("更新成功") : Result.fail("更新失败");
    }


}
